<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all" />
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/component.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/fixtable/css/normalize.css" rel="stylesheet">
<link href="<?php echo URL::base() ?>media/vendor/css/jquery-ui-timepicker-addon.min.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.core.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.widget.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.position.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.autocomplete.min.js"></script> 
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.7.1.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-addon.min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-timepicker-zh-CN.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>	
<style>.mypage{display: none;}.mypage .num{color: red;}</style>
<script type="text/javascript">
//ajax 请求数据
url='';
function get_pandian(url){
    var dialog = art.dialog({title: '提示',icon:'question',lock: true});
    dialog.content('<p>数据查询中,请稍后...<p>');
    $.get(url, {
        sku: $(".form-horizontal input[name='sku']").val(),
        warehouseid : $("#warehouseid").val(),
        export_tax_rebate: $(".form-horizontal select[name='export_tax_rebate']").val(),
        enterprise_dominant: $(".form-horizontal select[name='enterprise_dominant']").val(),
        username: $(".form-horizontal input[name='username']").val(),
        supplier:$(".form-horizontal input[name='supplier']").val(),
        batch_code:$(".form-horizontal input[name='batch_code']").val(),
        per_page: $(".form-horizontal select[name='per_page']").val(),
        type: $(".form-horizontal select[name='type']").val(),
        sortcondition: $(".form-horizontal select[name='sortcondition']").val(),
        order: $(".form-horizontal select[name='order']").val(),
        start_time: $(".form-horizontal input[name='start_time']").val(),
        end_time: $(".form-horizontal input[name='end_time']").val(),
    }, function(data){
        $('#table_content').empty();
        $('#table_content').html(data);
        $('#pager_links').empty();
        $('.mypage').clone().appendTo('#pager_links').show();
        dialog.close();
    });
}
$(function(){
    var startDateTextBox = $('#start');
    var endDateTextBox = $('#end');
    startDateTextBox.datetimepicker({
        dateFormat: 'yy-mm-dd',
        timeFormat: 'HH:mm:ss',
        onClose: function(dateText, inst) {
            if (endDateTextBox.val() != '') {
                var testStartDate = startDateTextBox.datetimepicker('getDate');
                var testEndDate = endDateTextBox.datetimepicker('getDate');
                if (testStartDate > testEndDate)
                    endDateTextBox.datetimepicker('setDate', testStartDate);
            }
            else {
                endDateTextBox.val(dateText);
            }
        },
        onSelect: function (selectedDateTime){
            endDateTextBox.datetimepicker('option', 'minDate', startDateTextBox.datetimepicker('getDate') );
        }
    });
    endDateTextBox.datetimepicker({
        dateFormat: 'yy-mm-dd',
        timeFormat: 'HH:mm:ss',
        onClose: function(dateText, inst) {
           if (startDateTextBox.val() != '') {
               var testStartDate = startDateTextBox.datetimepicker('getDate');
               var testEndDate = endDateTextBox.datetimepicker('getDate');
               if (testStartDate > testEndDate)
                   startDateTextBox.datetimepicker('setDate', testEndDate);
           }
           else {
               startDateTextBox.val(dateText);
           }
        },
        onSelect: function (selectedDateTime){
           startDateTextBox.datetimepicker('option', 'maxDate', endDateTextBox.datetimepicker('getDate') );
        }
    });
    $("#search").click(function(){
        url='<?php echo URL::base() ?>inventory/report/in_search';
        get_pandian(url);
    });

    $( "#search1" ).autocomplete({
        source:'<?php echo URL::base() ?>inventory/deliverycheck/check_allsupp'
    });

    $("#newDown").click(function(){
        var sku = $(".form-horizontal input[name='sku']").val();
        var warehouseid = $("#warehouseid").val();
        var export_tax_rebate = $(".form-horizontal select[name='export_tax_rebate']").val();
        var enterprise_dominant = $(".form-horizontal select[name='enterprise_dominant']").val();
        var username = $(".form-horizontal input[name='username']").val();
        var supplier = $(".form-horizontal input[name='supplier']").val();
        var type = $(".form-horizontal select[name='type']").val();
        var sortcondition = $(".form-horizontal select[name='sortcondition']").val();
        var	order = $(".form-horizontal select[name='order']").val();
        var	start_time = $(".form-horizontal input[name='start_time']").val();
        var	end_time = $(".form-horizontal input[name='end_time']").val();
        var	batch_code = $(".form-horizontal input[name='batch_code']").val();
        var uri = url.split('?')[1];
        if (!uri) {
            uri='export_tax_rebate=' + export_tax_rebate + '&enterprise_dominant=' + enterprise_dominant +
                '&sku=' + sku + '&username=' + username + '&supplier=' + supplier + '&type=' + type +
                '&sortcondition=' + sortcondition + '&start_time=' + start_time + '&batch_code=' + batch_code +
                '&end_time='+end_time+'&order='+order + '&warehouseid=' + warehouseid;
        }
        window.location.href = "<?php echo URL::base()?>inventory/report/newDownload?"+uri;
    });
    //绑定未来事件
    $(document).on('click', '.pagination a', function(e){
        e.preventDefault();
        url =$(this).attr('href');
        if(url.length){
            get_pandian(url);
        }
    });
    
    // 查询供应商自动提示补全
    $("#supplier_name").autocomplete({
       autoFocus: true,
       minLength: 0,
       autoFill: true,
       source: '<?php echo URL::base(true)?>purchase/get_supplier',
       select: function (event, ui) {
           //从建议列表中选中之后触发的事件
           $("#supplier_name").val(ui.item.name);
           return false;
       }
    });
});
</script>

<form class="form-horizontal" id="postform">
    <div class="control-group">
        <label class="control-label w-label">仓库ID: </label>
        <div class="controls">
        <select name="warehouseid" id="warehouseid">
            <option value="-1">全部</option>
            <?php if(isset($warehouses) and $warehouses){
                foreach($warehouses as $k => $warehouse){
                    ?>
                    <option value="<?php echo $warehouse['id']; ?>"><?php echo $warehouse['name'] ?></option>
                <?php }
            } ?>
        </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label w-label">SKU:</label>
        <div class="controls">
            <input type="text"   name='sku' value="">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label w-label">供应商:</label>
        <div class="controls">
            <input type="text" id="supplier_name" name='supplier' value="">
        </div>
    </div>
    <div class="control-group adv hidden">
        <label class="control-label w-label">批次号:</label>
        <div class="controls">
            <input type="text"  id="batch_code"  name='batch_code' value="">
        </div>
    </div>
    <div class="control-group adv hidden">
        <label class="control-label w-label">操作员:</label>
        <div class="controls">
            <input type="text"  name='username' value="">
        </div>
    </div>
    <div class="control-group adv hidden">
        <label class="control-label w-label">入库类型:</label>
        <div class="controls">
            <select  name='type'>
                <option value="">选择（默认全部）</option>
                <?php foreach ($status as $st): ?>
                    <option value="<?php echo $st['number'] ?>"><?php echo $st['value'] ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    </div>
    <div class="control-group adv hidden">
        <label class="control-label w-label">公司主体: </label>
        <div class="controls">
            <select name="enterprise_dominant" id="enterprise_dominant">
                <option value="-1">全部</option>
                <?php if(isset($enterprise_dominant) and $enterprise_dominant){
                    foreach($enterprise_dominant as $k => $v){
                ?>
                <option value="<?php echo $k ?>"><?php echo isset($enterprise_dominant[$k])?$enterprise_dominant[$k]:'' ?></option>
                <?php 
                    }
                } 
                ?>
            </select>
        </div>
    </div>
    <div class="control-group adv hidden">
        <label class="control-label w-label">出口退税: </label>
        <div class="controls">
            <select name="export_tax_rebate" id="export_tax_rebate">
                <option value="-1">全部</option>
                <?php 
                if(isset($export_tax_rebate) and $export_tax_rebate){
                    foreach($export_tax_rebate as $k => $v){
                ?>
                <option value="<?php echo $k ?>"><?php echo isset($export_tax_rebate[$k])?$export_tax_rebate[$k]:'' ?></option>
                <?php 
                    }
                } 
                ?>
            </select>
        </div>
    </div>
    <div class="control-group adv hidden">
        <label class="control-label w-label">自定义页数:</label>
        <div class="controls">
            <select  name='per_page'>
                <option value="">选择（默认15）</option>
                <option value='15'>15</option>
                <option value='30'>30</option>
                <option value='50'>50</option>
            </select>
        </div>
    </div>
    <div class="control-group hidden">
        <label class="control-label w-label">排序条件:</label>
        <div class="controls">
            <select  name='sortcondition' >
                <option value="3">选择（默认入库时间）</option>
                <option value='1'>SKU</option>
                <option value='2'>供应商</option>
                <option value='3'>入库日期</option>
            </select>
        </div>
    </div>
    <div class="control-group hidden">
        <label class="control-label w-label">排序方式:</label>
        <div class="controls">
            <select name='order' >
                <option value='2'>降序</option>
                <option value='1'>升序</option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label w-label" for="inputPassword">入库日期:</label>
        <div class="controls ">
            <input type="text" name='start_time' id="start" style=" width:164px; margin-right:5px;" > ~
            <input type="text" name='end_time' id="end" >
        </div>
        <div style=" margin-top:10px;">
            <div class="btn btn-info" id="search" style="margin-left:110px;">查询</div>
            <input type="reset" style="margin-left:10px;" class="btn" value="重置">
            <div class="btn" id='newDown' style="margin-left:10px">下载</div>
            <a href="javascript:;" class="btn btn-link" onclick="javascript:$('#postform .adv').toggleClass('hidden');">更多筛选条件</a>
        </div>
    </div>
</form>
<table class="table table-hover">
    <thead>
        <tr>
            <th>入库单号</th>
            <th>SKU</th>
            <th>中文名称</th>
            <th>入库量</th>
            <th style="width:50px">仓库</th>
            <th>批次号</th>
            <th>入库时间</th>
            <th>入库类型</th>
            <th>预约单号</th>
            <th>供应商</th>
            <th>退税类型</th>
            <th>公司主体</th>
            <th>储位</th>
            <th>单价</th>
            <th>成本</th>
            <th>金额</th>
            <th>备注</th>
            <th>采购备注</th>
            <th>操作人</th>
        </tr>
    </thead>
    <tbody id='table_content'>
    </tbody>
</table>
<div id="pager_links"></div>
